<template>
  <el-table :data="list" border @selection-change="handleSelection">
    <el-table-column type="selection" width="55" />
    <el-table-column prop="id" label="id" width="55" />
    <el-table-column prop="name" label="姓名" />
    <el-table-column prop="phone" label="电话" />
    <el-table-column prop="status" label="状态">
      <template slot-scope="{ row }">
        <span>{{ row.status === 1 ? '在职' : '离职' }}</span>
      </template>
    </el-table-column>
    <el-table-column prop="count" label="每日配量" />
    <el-table-column prop="newCustomerCount" label="已分配" />
    <el-table-column prop="login" label="登录">
      <template slot-scope="{ row }">
        <span>{{ row.login === 1 ? '允许' : '否' }}</span>
      </template>
    </el-table-column>
    <el-table-column prop="receive" label="分配新客户">
      <template slot-scope="{ row }">
        <span>{{ row.receive === 1 ? '接受' : '否' }}</span>
      </template>
    </el-table-column>
    <el-table-column prop="rest" label="休息模式">
      <template slot-scope="{ row }">
        <span>{{ row.rest == 1 ? '开启' : '未开启' }}</span>
      </template>
    </el-table-column>
    <el-table-column prop="isLogin" label="登录状态">
      <template slot-scope="{ row }">
        <span>{{ row.isLogin ? '已登录' : '未登录' }}</span>
      </template>
    </el-table-column>
    <el-table-column prop="shopName" label="门店" />
    <el-table-column prop="teamName" label="团队" />
    <el-table-column prop="roleName" label="岗位" />
    <el-table-column label="操作" width="260px" align="center">>
      <template slot-scope="{ row }">
        <el-button type="primary" plain size="mini" @click="edit(row)">编辑</el-button>
        <el-button type="primary" plain size="mini" @click="updateWorker(row)">离职回收客户</el-button>
        <el-button type="danger" plain size="mini" @click="removeWorker(row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>
<script>
import { UPDATE_EMPLOYEE_STATE, DELETE_EMPLOYEE_STATE } from "@/http/customer";
import { showModal, showToast } from "@/utils/util";
export default {
  name: "StoreTable",
  props: {
    list: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      idList: [],
    };
  },
  methods: {
    handleSelection(list) {
      this.idList = list.map(({ id }) => id);
    },
    edit(row) {
      this.$emit("add",row);
      // this.$router.push({
      //   name: "StaffCreate",
      //   params: {
      //     row: JSON.stringify(row),
      //     type: "edit",
      //   },
      // });
      //console.log("操作");
    },

    // 离职员工回收
    updateWorker(row) {
      let _this = this;
      showModal({
        message: `确认员工${row.name}离职, 并回收客户到团队么`,
        showCancelButton: true,
        success: function () {
          UPDATE_EMPLOYEE_STATE({ id: row.id }).then((res) => {
            if (res.code == 200) {
              showToast({
                message: res.message,
                type: "success",
              });
              _this.$emit("change");
            }
          });
        },
      });
    },

    // 删除员工
    removeWorker(row) {
      let _this = this;
      showModal({
        message: `确认删除员工${row.name}吗？`,
        showCancelButton: true,
        success: function () {
          DELETE_EMPLOYEE_STATE({ id: row.id }).then((res) => {
            if (res.code == 200) {
              showToast({
                message: res.message,
                type: "success",
              });
              _this.$emit("change");
            }
          });
        },
      });
    },
  },
};
</script>
